﻿using System.ComponentModel.DataAnnotations;
using System;
using MyCommunity.Models;
using System.Web.Mvc;
using System.Data.Entity;
using System.Collections.Generic;


public class UserViewModel
{
    private User obj;

    public UserViewModel() {
        this.obj = new User();
    }

    public UserViewModel(User obj) {
        this.Id = obj.Id;
        this.Firstname = obj.Firstname;
        this.Lastname = obj.Lastname;
        this.Mail = obj.Mail;
        this.Birthday = obj.Birthday;
        this.isActive = obj.IsActive;
        this.isAdmin = obj.IsAdmin;
    }

    public int Id { get; set; }

    [Required]
    [DataType(DataType.EmailAddress)]
    [Display(Name = "Email address")]
    public string Mail { get; set; }

    [Required]
    public string Firstname { get; set; }

    [Required]
    public string Lastname { get; set; }

    public Boolean isActive { get; set; }

    public Boolean isAdmin { get; set; }

    [DataType(DataType.DateTime)]
    [RegularExpression(@"^(([0-2]\d|[3][0-1])\.([0]\d|[1][0-2])\.[1-2][0-9]\d{2})\s[0-2][0-9]\:[0-6][0-9]\:[0-6][0-9]$", ErrorMessage = "Es muss sich um ein gültiges Datum handeln!")]
    public DateTime? Birthday { get; set; }

    public DbSet<Event> Events { get; set; }

    public Boolean isLoggedInAdmin { get; set; }

    public int loggedInUserId { get; set; }

    public void ApplyChanges(User obj)
    {
        obj.Firstname = this.Firstname;
        obj.Lastname = this.Lastname;
        obj.Mail = this.Mail;
        obj.Birthday = this.Birthday;
        obj.IsActive = this.isActive;
        obj.IsAdmin = this.isAdmin;
    }

    public void SetAttendance(List<UserEventAttendance> attendance)
    {
        _attendance = attendance;
    }

    public List<UserEventAttendance> UserEventAttendance { get { return _attendance; } }
    private List<UserEventAttendance> _attendance;

}